home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xmcd-1.4 / misc.d / makeshar.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1995-05-10  |  4.3 KB  |  241 lines

  1. #!/bin/sh
  2. #
  3. # @(#)makeshar.sh    5.2 94/12/28
  4. #
  5. # Make software source code release in shar format
  6. #
  7. # Note: This script was designed to work with the shar program
  8. #       as provided in the "cshar" package from Rich Salz.  Other
  9. #       shar implementations may support different command line
  10. #       parameters which is incompatible with cshar.  This script
  11. #       must be modified in order to be used with those.
  12. #
  13. #    xmcd  - Motif(tm) CD Audio Player
  14. #    cda   - Command-line CD Audio Player
  15. #    libdi - CD Audio Player Device Interface Library
  16. #
  17. #    Copyright (C) 1995  Ti Kan
  18. #    E-mail: ti@amb.org
  19. #
  20. #    This program is free software; you can redistribute it and/or modify
  21. #    it under the terms of the GNU General Public License as published by
  22. #    the Free Software Foundation; either version 2 of the License, or
  23. #    (at your option) any later version.
  24. #
  25. #    This program is distributed in the hope that it will be useful,
  26. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  28. #    GNU General Public License for more details.
  29. #
  30. #    You should have received a copy of the GNU General Public License
  31. #    along with this program; if not, write to the Free Software
  32. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33. #
  34.  
  35. SRCLIST=misc.d/SRCLIST
  36. VERS=`grep "VERSION=" $SRCLIST | sed 's/^.*VERSION=//'`
  37. BNAME=xmcdshar
  38. MAXSZ=60000
  39. TMP1=/tmp/dlist1.$$
  40. TMP2=/tmp/dlist2.$$
  41. TMP3=/tmp/prep.$$
  42. TMP4=/tmp/flist1.$$
  43. TMP5=/tmp/flist2.$$
  44.  
  45. trap "rm -f $TMP1 $TMP2 $TMP3 $TMP4 $TMP5" 0 1 2 3 5 15
  46.  
  47.  
  48. #
  49. # Register a list of files to be shar'ed into a single archive
  50. #
  51. prep_shar()
  52. {
  53.     SHARNUM=`expr $SHARNUM + 1`
  54.     SHARTOT=$SHARNUM
  55.  
  56.     rm -f $TMP1 $TMP2
  57.  
  58.     for f in $*
  59.     do
  60.         dname=$f
  61.         while :
  62.         do
  63.             dname=`dirname $dname`
  64.             if [ $dname != . ]
  65.             then
  66.                 $ECHO "$dname" >>$TMP1
  67.             else
  68.                 break
  69.             fi
  70.         done
  71.     done
  72.  
  73.     if [ -r $TMP1 ]
  74.     then
  75.         sort $TMP1 | uniq >$TMP2
  76.         for f in `cat $TMP2`
  77.         do
  78.             $ECHO "$f \c" >>$TMP3
  79.         done
  80.     fi
  81.  
  82.     $ECHO "$*" >>$TMP3
  83.  
  84.     rm -f $TMP1 $TMP2
  85.  
  86.     $ECHO "  == Part $SHARNUM processing done ==\n"
  87. }
  88.  
  89.  
  90. #
  91. # Create all shar files
  92. #
  93. do_shar()
  94. {
  95.     if [ ! -r $TMP3 ]
  96.     then
  97.         $ECHO "Error: cannot open $TMP3"
  98.         exit 1
  99.     fi
  100.  
  101.     $AWK '
  102.     {
  103.         printf("\t%s.%02d\n", bname, NR);
  104.         cmd = sprintf("shar -n%d -e%s -o %s.%02d -t %s %s\n",
  105.             NR, tot, bname, NR,
  106.             "\"Read the README and INSTALL files for instructions.\"",
  107.             $0)
  108.         system(cmd)
  109.     }
  110.     ' tot=$SHARTOT bname=$BNAME $TMP3
  111. }
  112.  
  113.  
  114. #
  115. # Main execution starts here
  116. #
  117. SHARNUM=0
  118.  
  119. # Use Sysv echo if possible
  120. if [ -x /usr/5bin/echo ]                # SunOS SysV echo
  121. then
  122.     ECHO=/usr/5bin/echo
  123. elif [ -z "`(echo -e a) 2>/dev/null | fgrep e`" ]    # GNU bash, etc.
  124. then
  125.     ECHO="echo -e"
  126. else                            # generic SysV
  127.     ECHO=echo
  128. fi
  129.  
  130. # Use nawk instead of awk is available
  131. if (echo "" | nawk '{ print }') >/dev/null 2>&1
  132. then
  133.     AWK=nawk
  134. else
  135.     AWK=awk
  136. fi
  137.  
  138. # Figure out whether to use the -g option to ls
  139. if [ `ls -ld / | wc -w` -eq 8 ]
  140. then
  141.     LSCMD="ls -lg"
  142. else
  143.     LSCMD="ls -l"
  144. fi
  145.  
  146. CURDIR=`pwd`
  147. if [ `basename "$CURDIR"` = misc.d ]
  148. then
  149.     cd ..
  150. elif [ ! -f install.sh ]
  151. then
  152.     $ECHO "You must run the makeshar.sh script while in the xmcd"
  153.     $ECHO "source code distribution top-level directory or in the"
  154.     $ECHO "misc.d subdirectory."
  155.     exit 1
  156. fi
  157.  
  158. if [ ! -r $SRCLIST ]
  159. then
  160.     $ECHO "Error: Cannot open $SRCLIST"
  161.     exit 2
  162. fi
  163.  
  164. $ECHO "Xmcd/cda v$VERS source code shar format release utility"
  165. $ECHO "\nCreating file lists.  This will take a few minutes..."
  166.  
  167. rm -f $TMP3
  168. $AWK '!/^#/ { print $1 }' $SRCLIST >$TMP4
  169.  
  170. # Extract names of all files bigger than MAXSZ first
  171. for i in `cat $TMP4`
  172. do
  173.     ssize=`$LSCMD $i | $AWK '
  174.         BEGIN { n = 0 }
  175.         { n += $5 }
  176.         END { printf("%d\n", n) }
  177.     '`
  178.  
  179.     if [ $ssize -gt $MAXSZ ]
  180.     then
  181.         BIGFILES="$BIGFILES $i"
  182.     else
  183.         echo "$i" >>$TMP5
  184.     fi
  185. done
  186.  
  187. $ECHO ""
  188.  
  189.  
  190. # Process all other files
  191. while :
  192. do
  193.     cp $TMP5 $TMP4
  194.     >$TMP5
  195.  
  196.     if [ ! -s $TMP4 ]
  197.     then
  198.         break
  199.     fi
  200.  
  201.     ssize=0
  202.     THISSHAR=""
  203.  
  204.     for i in `cat $TMP4` _xoxo_
  205.     do
  206.         if [ $i = _xoxo_ ]
  207.         then
  208.             prep_shar $THISSHAR
  209.             break
  210.         fi
  211.  
  212.         ssize=`$LSCMD $THISSHAR $i | $AWK '
  213.             BEGIN { n = 0 }
  214.             { n += $5 }
  215.             END { printf("%d\n", n) }
  216.         '`
  217.  
  218.         if [ $ssize -le $MAXSZ ]
  219.         then
  220.             THISSHAR="$THISSHAR $i"
  221.             $ECHO "  Adding $i"
  222.         else
  223.             echo "$i" >>$TMP5
  224.         fi
  225.     done
  226. done
  227.  
  228. # Handle big files
  229. for i in $BIGFILES
  230. do
  231.     $ECHO "  Adding $i"
  232.     prep_shar $i
  233. done
  234.  
  235. # Create the shar files
  236. $ECHO "\nCreating shar files...\n"
  237. do_shar
  238.  
  239. exit 0
  240.  
  241.